package org.gulugulubiao.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.gulugulubiao.annoctation.AutoFill;
import org.gulugulubiao.entity.User;
import org.gulugulubiao.enumeration.OperationType;

@Mapper
public interface UserMapper {
//    @Select("select * from sqlOnline.user where id = #{id}")
//    User queryById(Long id);


    /**
     * 根据用户名查询员工
     * @param username
     * @return User
     */
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    /**
     * 新增用户
     * @param user
     * @return
     */
    @Insert("insert into user(username, password, email, phone, gender, birthdate, status, create_time, update_time,role) values(#{username}, #{password}, #{email}, #{phone}, #{gender}, #{birthdate}, #{status}, #{createTime}, #{updateTime},#{role})")
    void insert(User user);

    /**
     *  用户分页查询
     * @param
     * @return
     */
    Page<User> getUserList();


    /**
     *  显示id对应的用户信息
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getUserById(Integer userId);


    /**
     * 根据主键动态修改属性
     * @param user
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(User user);

    /**
     * 根据用户id查询员工
     * @param id
     * @return User
     */
    @Select("select * from user where id = #{id}")
    User getById(Integer id);

    /**
     * 根据用户id删除用户
     * @param id
     */
    @Delete("delete from user where id = #{id}")
    void delete(Integer id);
}
